package com.nineclock.common.exception;

import com.nineclock.common.entity.Result;
import com.nineclock.common.enums.ResponseEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class BasicExceptionAdvice {

//    捕获到的自定义异常
    @ExceptionHandler(NcException.class)
    public Result ncException(NcException e){
        e.getStackTrace();
        return Result.errorCodeMessage(e.getCode(),e.getMessage());
    }

//    捕获其它异常
    @ExceptionHandler(Exception.class)
    public Result exception(Exception e){
        log.error(e.getMessage(),e);
        return Result.errorCodeMessage(ResponseEnum.SERVER_ERROR.getCode(),ResponseEnum.SERVER_ERROR.getMessage());
    }

}
